package com.cskaoyan.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 请求头限定 headers属性
 * @author stone
 * @date 2022/12/23 10:03
 */
@Controller
@RequestMapping("header")
public class HeaderLimitController {

    // 既要携带abc这个请求头，也要携带def这个请求头
    @RequestMapping(value = "limit",headers = {"abc","def"})
    @ResponseBody
    public String headerLimit() {
        return "ok";
    }

    @RequestMapping(value = "consumes",consumes = "abc/def")
    @ResponseBody
    public String contentTypeLimit() {
        return "ok";
    }

    @RequestMapping(value = "produces",produces = "application/json")
    @ResponseBody
    public String acceptLimit(){
        return "ok";
    }

    // 希望接收到正文的charset为utf-8
    @RequestMapping(value = "chinese",produces = "text/html;charset=utf-8")
    @ResponseBody
    public String chinese() {
        return "这是中文";
        //响应这个字符串的是SpringMVC给我们去响应这个字符串，
        // 默认的值，响应头中的Content-Type的值变为了text/html;charset-iso-8859-1
        // 昨天在微信群里给大家发了解决方案
    }
}
